var UserInfo = (function () {
    var instance;

    function init() {
        // 单例
        // 私有方法和变量
        var userData;
        var token;
        var uid;   //UID
        var phone;
        var gameInfo;
        var seatId;

        return {
            setUserInfo: function (data) {
                userData = data.data;
                token = data.token;
                uid = data.uid;
            },
            setUserData: function (data) {
                userData = data;
            },
            getUserData: function () {
                return userData;
            },
            setToken: function (token) {
                localStorage.setItem('token', token);
            },
            getToken: function () {
                if (localStorage.getItem('token')) {
                    token = localStorage.getItem('token');
                }
                return token;
            },
            removeToken: function () {
                localStorage.setItem('token', '');
            },
            setUid: function (data) {
                uid = data;;
            },
            getUid: function () {
                return uid;
            },
            setPhone: function (data) {
                localStorage.setItem('phone', data);
            },
            getPhone: function (data) {
                if (localStorage.getItem('phone')) {
                    phone = localStorage.getItem('phone');
                }
                return phone;
            },
            setGameInfo: function (data) {
                gameInfo = data;
            },
            getGameInfo: function (data) {
                return gameInfo;
            },
            setSeatId: function (data) {
                seatId = data;
            },
            getSeatId: function (data) {
                return seatId;
            },


        };
    };

    return {
        // 如果存在获取此单例实例，如果不存在创建一个单例实例
        getInstance: function () {
            if (!instance) {
                instance = init();
            }
            return instance;
        }
    };
})();
